<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点我获取数据</button>
    <script>
        const btn = document.querySelector("button")
        btn.onclick = function(){
            /* 
                只有ajax请求才会出现跨域
                
                跨域请求
                    发送请求的时候,没有遵守同源策略
                        同源策略
                            同协议
                            同域名
                            同端口
            */
            const xhr = new XMLHttpRequest();
            xhr.open("GET","https://www.runoob.com/try/ajax/jsonp.php?jsoncallback=callbackFunction");
            xhr.send();
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4 && /2\d{2}/.test(xhr.status)){
                    console.log(xhr.responseText);
                }
            }
        }
    </script>
</body>
</html>